# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>
# Contributor: riai <riai@bigfoot.com>, Ben <ben@benmazer.net>

pkgbase=sip
pkgname=('sip' 'python-sip' 'python2-sip' 'python-sip-pyqt5' 'python2-sip-pyqt5')
pkgver=4.19.13
pkgrel=1
arch=('x86_64')
url='http://www.riverbankcomputing.com/software/sip/intro'
license=('custom:"sip"')
makedepends=('python' 'python2')
source=("http://sourceforge.net/projects/pyqt/files/sip/sip-$pkgver/sip-$pkgver.tar.gz")
sha256sums=('e353a7056599bf5fbd5d3ff9842a6ab2ea3cf4e0304a0f925ec5862907c0d15e')

prepare() {
  mkdir -p build{,-py2,-pyqt5,-pyqt5-py2}
}

build() {
  cd "$srcdir"/build
  python ../sip-$pkgver/configure.py CFLAGS="$CFLAGS" LFLAGS="$LDFLAGS"
  make

  cd "$srcdir"/build-py2
  python2 ../sip-$pkgver/configure.py CFLAGS="$CFLAGS" LFLAGS="$LDFLAGS"
  make

  cd "$srcdir"/build-pyqt5
  python ../sip-$pkgver/configure.py CFLAGS="$CFLAGS" LFLAGS="$LDFLAGS" --sip-module PyQt5.sip --no-tools
  make

  cd "$srcdir"/build-pyqt5-py2
  python2 ../sip-$pkgver/configure.py CFLAGS="$CFLAGS" LFLAGS="$LDFLAGS" --sip-module PyQt5.sip --no-tools
  make
}

package_sip() {
  pkgdesc="A tool that makes it easy to create Python bindings for C and C++ libraries"
  depends=('glibc')

  cd build
  make DESTDIR="$pkgdir" install -C sipgen
# move sip.h to /usr/include
  mv "$pkgdir"/usr/include/{python*/sip.h,}
  rm -r "$pkgdir"/usr/include/python*

  install -Dm644 ../sip-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_python-sip() {
  pkgdesc="Python 3.x SIP bindings for C and C++ libraries"
  depends=('python')

  cd build
  make DESTDIR="$pkgdir" install
  rm -r "$pkgdir"/usr/{bin,include} # conflicts with sip

  install -Dm644 ../sip-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_python2-sip() {
  pkgdesc="Python 2.x SIP bindings for C and C++ libraries"
  depends=('python2')

  cd build-py2
  make DESTDIR="$pkgdir" install
  rm -r "$pkgdir"/usr/{bin,include} # conflicts with sip

  install -Dm644 ../sip-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_python-sip-pyqt5() {
  pkgdesc="Python 3.x SIP bindings for C and C++ libraries (PyQt5 version)"
  depends=('python')

  cd build-pyqt5
  make DESTDIR="$pkgdir" install

  install -Dm644 ../sip-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}

package_python2-sip-pyqt5() {
  pkgdesc="Python 2.x SIP bindings for C and C++ libraries (PyQt5 version)"
  depends=('python2')

  cd build-pyqt5-py2
  make DESTDIR="$pkgdir" install

  install -Dm644 ../sip-$pkgver/LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
